package model

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"mynetdisk/utils"
)

/**
 *@Author tudou
 *@Date 2019/8/24
 **/

var DB *gorm.DB

//var dbUrl="root:@tcp(127.0.0.1:3306)/demo?parseTime=true&charset=utf8&loc=Local"
var dbUrl="root:123456@tcp(172.17.0.2:3306)/demo?parseTime=true&charset=utf8&loc=Local"

func ModelInit(){
	var err error
	DB,err = gorm.Open("mysql",dbUrl)
	utils.CheckErr(err,"can't connect the database")
	DB.DB().SetMaxOpenConns(100)
	DB.DB().SetMaxIdleConns(10)
	DB.SingularTable(true)
}

func ModelClose(){
	err:=DB.DB().Close()
	utils.CheckErr(err,"close the database failed")
}